package dhm.com.hpx.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.hpx.R;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.entity.FavoriteArticleBean;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class MessageColletArticleadapter extends RecyclerView.Adapter<MessageColletArticleadapter.ViewHolder> {

    private Context context;


    List<FavoriteArticleBean.DataBean> list=new ArrayList<>();

    public MessageColletArticleadapter(Context context) {
        this.context = context;
    }


    public void setList(List<FavoriteArticleBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.message_like, null);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.image.setImageURI(Constant.PATH+list.get(i).getCoverImg());
        viewHolder.content.setText(list.get(i).getArticleTitle());
        viewHolder.time.setText(list.get(i).getArticleId()+"");
        viewHolder.type.setText("收藏");
        viewHolder.likeType.setImageResource(R.mipmap.article);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick.item(i);
            }
        });
        viewHolder.del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onIntentClick.item(i);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView image;
        public TextView content;
        public TextView time;
        public TextView type;
        public TextView del;
        public ImageView likeType;
        public RelativeLayout itemView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            content=itemView.findViewById(R.id.content);
            type=itemView.findViewById(R.id.type);
            likeType=itemView.findViewById(R.id.like_type);
            time=itemView.findViewById(R.id.time);
            image=itemView.findViewById(R.id.image);
            del=itemView.findViewById(R.id.del);
            this.itemView=itemView.findViewById(R.id.itemview);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int position);
    }
}

